// this is vue config
// /* eslint-disable */
module.exports = {
  lintOnSave: false,
  pwa: {
    iconPaths: {
      favicon32: 'favicon.ico',
      favicon16: 'favicon.ico',
      appleTouchIcon: 'favicon.ico',
      maskIcon: 'favicon.ico',
      msTileImage: 'favicon.ico'
    }
  },
  chainWebpack: config => {
    config
      .plugin("define")
      .when(process.env.NODE_ENV === 'production', plugin => {
        plugin.tap(definitions => {
          definitions[0] = Object.assign(definitions[0], {
            ENV: "ENV"
          });
          return definitions;
        });
      });
    config.plugin("copy").tap(args => {
      args[0].push({
        from: require('path').resolve("env.js"),
        to: require('path').resolve("dist")
      });
      return args;
    });
    // physics
    if (process.env.NODE_ENV === 'physics') {
      let filenameHashing = true;
      const filename = `js/[name]${filenameHashing ? '.[hash:8]' : ''}.js`
      config// .mode('production')
        .devtool('source-map')//false source-map
        .output
        .filename(filename)
        .chunkFilename(filename)
      // keep chunk ids stable so async chunks have consistent hash (#1916)
      config
        .plugin('named-chunks')
        .use(require('webpack/lib/NamedChunksPlugin'), [chunk => {
          if (chunk.name) {
            return chunk.name
          }
          const hash = require('hash-sum')
          const joinedHash = hash(
            Array.from(chunk.modulesIterable, m => m.id).join('_')
          )
          return `chunk-` + joinedHash
        }])
    };
  },
  configureWebpack: config => {
    if (process.env.NODE_ENV === 'physics') {
      // 为物理环境修改webpack配置...
      let UglifyPlugin = require('uglifyjs-webpack-plugin');
      // 将每个依赖包打包成单独的js文件
      config.plugins.push(
        new UglifyPlugin({
          uglifyOptions: {
            compress: {
              warnings: false,
              drop_debugger: true,
            },
            warnings: false,
          },
          sourceMap: false,
          parallel: true,//使用多进程并行运行来提高构建速度。默认并发运行数：os.cpus().length - 1。
        })
      );
    }
  }
  //devServer: {
  // proxy: {
  //"/GC": {
  //   target: "http://10.19.248.200:30830",
  //      pathRewrite: {
  //        "^/GC": ""
  //      },
  //    ws: true,
  //  changeOrigin: true
  //     },
  //     "/ZC": {
  //     target: "http://10.19.248.200:31678",
  //   pathRewrite: {
  //       "^/ZC": ""
  //    },
  //    ws: true,
  //    changeOrigin: true
  //  },
  //  "/ZL": {
  //   target: "http://10.19.248.200:31688",
  //   pathRewrite: {
  //    "^/ZL": ""
  //  },
  //   ws: true,
  //  changeOrigin: true
  //  },
  //  "/FW": {
  //    target: "http://10.19.248.200:31289",
  //    pathRewrite: {
  //     "^/FW": ""
  //  },
  //    ws: true,
  //    changeOrigin: true
  //  }
  // }
  // }
};
